package com.ssrs.platform.code;

import com.ssrs.framework.extend.annotation.ExtendItem;
import com.ssrs.platform.FixedCodeType;
import com.ssrs.platform.PlatformPlugin;
import com.ssrs.platform.extend.CodeService;

import java.util.HashMap;
import java.util.Map;
/**
 * 配置项数据类型
 *
 * @author ssrs
 */
@ExtendItem(
        plugin = PlatformPlugin.class,
        extendService = CodeService.class,
        description = "配置项数据类型代码项"
)
public class DataType extends FixedCodeType {
    public static final String CODETYPE = "DataType";

    public static final String SHORTTEXT = "ShortText";
    public static final String MEDIUMTEXT = "MediumText";
    public static final String LARGETEXT = "LargeText";
    public static final String CLOBTEXT = "ClobText";
    public static final String LONG = "Long";
    public static final String DOUBLE = "Double";
    public static final String DATETIME = "Datetime";

    public DataType() {
        super(CODETYPE, "数据类型", false, false);
        addFixedItem(MEDIUMTEXT, "字符串(200)", null);
        addFixedItem(SHORTTEXT, "字符串(50)", null);
        addFixedItem(LARGETEXT, "字符串(2000)", null);
        addFixedItem(CLOBTEXT, "字符串(不限长度)", null);
        addFixedItem(LONG, "长整型", null);
        addFixedItem(DOUBLE, "双字节浮点", null);
        addFixedItem(DATETIME, "日期时间", null);
    }

    public static boolean isClobText(String type) {
        return CLOBTEXT.equals(type);
    }

    public static boolean isDate(String type) {
        return DATETIME.equals(type);
    }

    public static boolean isDouble(String type) {
        return DOUBLE.equals(type);
    }

    public static boolean isLargeText(String type) {
        return LARGETEXT.equals(type);
    }

    public static boolean isLong(String type) {
        return LONG.equals(type);
    }

    public static boolean isMediumText(String type) {
        return MEDIUMTEXT.equals(type);
    }

    public static boolean isShortText(String type) {
        return SHORTTEXT.equals(type);
    }

    private static class TypesHolder {
        final static Map<String, Integer> TYPES = new HashMap<>();

        static {
            TYPES.put(SHORTTEXT, 25);
            TYPES.put(MEDIUMTEXT, 25);
            TYPES.put(LARGETEXT, 4);
            TYPES.put(CLOBTEXT, 1);
            TYPES.put(LONG, 10);
            TYPES.put(DOUBLE, 10);
            TYPES.put(DATETIME, 10);
        }
    }

    public static Map<String, Integer> getFieldTypes() {
        return TypesHolder.TYPES;
    }
}
